package com.train.member.controller;

import com.train.common.resp.CommonResp;
import com.train.member.req.MemberLoginReq;
import com.train.member.req.MemberRegiterReq;
import com.train.member.req.MemberSendCodeReq;
import com.train.member.resp.MemberLoginResp;
import com.train.member.service.Memberservice;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Resource
    private Memberservice memberservice;
    @GetMapping("/count")
    public CommonResp<Integer> count(){
        int count= memberservice.count();
        //CommonResp<Integer> commonResp=new CommonResp<>();
        //commonResp.setContent(count);
        return new CommonResp<>(count);
    }

    @PostMapping("/register")
    public CommonResp<Long> register(@Valid MemberRegiterReq req){
        long register = memberservice.register(req);
        //CommonResp<Long> commonResp=new CommonResp<>();
        //commonResp.setContent(register);
        return new CommonResp<>(register);
    }
    @PostMapping("/send-code")
    public CommonResp<Long> sendCode(@Valid @RequestBody MemberSendCodeReq req){
        memberservice.sendCode(req);
        //CommonResp<Long> commonResp=new CommonResp<>();
        //commonResp.setContent(register);
        return new CommonResp<>();
    }
    @PostMapping("/login")
    public CommonResp<MemberLoginResp> login(@Valid @RequestBody MemberLoginReq req) {
        MemberLoginResp resp = memberservice.login(req);
        return new CommonResp<>(resp);
    }
}
